/*
 * 文件名： Header.java
 * 
 * 创建日期： 2016年11月23日
 *
 * Copyright(C) 2016, by <a href="mailto:liws@xingyuanauto.com">liws</a>.
 *
 * 原始作者: liws
 *
 */
package com.moli.iov.protocol.model;

import java.io.Serializable;

import com.moli.iov.protocol.codec.DataEncoder;
import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.CommandTag;
import com.moli.iov.protocol.enums.EncryptTag;
import com.moli.iov.protocol.enums.ResponseTag;
import com.moli.iov.util.ByteArrayUtil;



/**
 * 数据传输协议 头
 *
 * @author <a href="mailto:liws@xingyuanauto.com">liws</a>
 *
 * @version $Revision$
 *
 * @since 2016年11月23日
 */
@Serialize(unit="byte",isBigEndian=true)
public class Header implements Serializable{
	 /** 
	 */ 
	private static final long serialVersionUID = 1L;
	
	/**
	 * Header 报文长度
	 */
	public static final int header_offset = 24;
	
	/**
	 * 协议头 起始TAG
	 */
	@Serialize(unit = "byte", offset = 0, size = 2)
	public String startTag = "##";// 0x23,0x23

	/**
	 * 命令标识
	 */
	@Serialize(unit = "byte", offset = 2, size = 1)
	public CommandTag commandTag;

	/**
	 * 应答标志
	 */
	@Serialize(unit = "byte", offset = 3, size = 1)
	public ResponseTag responseTag;

	/**
	 * uid唯一标识码
	 */
	@Serialize(unit = "byte", offset = 4, size = 17)
	public String vin;

	/**
	 * 数据单元加密方式
	 */
	@Serialize(unit = "byte", offset = 21, size = 1)
	public EncryptTag encryptTag;

	/**
	 * 数据单元长度
	 */
	@Serialize(unit = "byte", offset = 22, size = 2)
	public short dataLen;

	
	 /**
	 *
	 * @see Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Header [startTag=");
		builder.append(startTag);
		builder.append(", commandTag=");
		builder.append(commandTag);
		builder.append(", responseTag=");
		builder.append(responseTag);
		builder.append(", vin=");
		builder.append(vin);
		builder.append(", encryptTag=");
		builder.append(encryptTag);
		builder.append(", dataLen=");
		builder.append(dataLen);
		builder.append("]");
		return builder.toString();
	}


	public static void main(String[] args) {
//		Header rBody = new Header();
//		rBody.commandTag = CommandTag.WOASIS_CUSTOMIZE_UP;
//		rBody.responseTag = ResponseTag.VIN_REPEAT;
//		rBody.vin = System.currentTimeMillis() + "";
//		rBody.encryptTag = EncryptTag.AES128_ENCRYPT;
//		DataEncoder<Header> reportEncoder = new DataEncoder<Header>();
//		try {
//			System.out.println(ByteArrayUtil.toHexString(reportEncoder.encode(rBody)));
//		}
//		catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
//		byte[] bytes = new byte[]
//                { 0x23, 0x23, 0x08, 0x01, 0x4c, 0x42, 0x39, 0x4b, 0x41, 0x44, 
//                        0x44, 0x42, 0x36, 0x47, 0x31, 0x5a, 0x4b, 0x4a, 0x31, 0x30, 0x31, 
//                        0x01, 0x00, 0x00, 0x5c };
//		byte[] byte1 = new byte[]
//		{	0x23,0x23
//		,0x01
//		,(byte) 0xFE
//		,0x36,0x36,0x31,0x44,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x32
//		,0x01
//		,0x00,0x2A
//		,0x12,0x06,0x0C,0x0E,0x0A,0x07
//		,0x00,0x13
//		,0x38,0x39,0x38,0x36,0x30,0x32,0x44,0x39,0x39,0x38,0x31,0x37,0x33,0x30,0x30,0x30,0x34,0x39,0x35,0x32
//		,0x01
//		,0x0C
//		,0x31,0x31,0x38,0x32,0x31,0x33,0x33,0x30,0x35,0x35,0x30,0x31
//		,(byte) 0xE2};
//
//
//		Header baseInfoReq = new Header();
//        DataDecoder<Header> decoder = new DataDecoder<>();
//        try {
//            decoder.decode(baseInfoReq, byte1);
//            System.out.println(baseInfoReq.toString());
//        }
//        catch (Exception e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }

		
		
	}
}
